﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Runtime.Serialization;

namespace RobotGerchik.DataClass
{
    /// <summary>
    /// Модель данных для строки Ledders
    /// </summary>
    [Serializable]
    public class TradesOpen : INotifyPropertyChanged, ISerializable
    {
        #region private

        //заявки на открытие позиций
        private DateTime _openDate;
        private string _openOperation;
        private int _openQuantity;
        private int _openBalance;
        private string _openStatusOrder;
        private int _openID;
        private long _openNumberOrder;
        private double _openPriceOrder;

        //заявки на закрытие позиций
        private DateTime _closeDate;
        private string _closeOperation;
        private int _closeQuantity;
        private int _closeBalance;
        private string _closeStatusOrder;
        private int _closeID;
        private long _closeNumberOrder;
        private double _closePriceOrder;

        //Стоп-заявки на закрытие позиции (Cтоп-лосс)
        private DateTime _StopLimitCloseDate;
        private string _StopLimitCloseOperation;
        private int _StopLimitCloseQuantity;
        private int _StopLimitCloseBalance;
        private string _StopLimitCloseStatusOrder;
        private string _StopLimitCloseResult;
        private int _StopLimitCloseID;
        private long _StopLimitCloseNumberOrder;
        private double _StopLimitclosePriceOrder;
        private long _StopLimitCloseNumberLinkidOrder;

        //Стоп-заявки на закрытие позиции (Cтоп-лосс)
        private DateTime _OrderFromStopLimitCloseDate;
        private string _OrderFromStopLimitCloseOperation;
        private int _OrderFromStopLimitCloseQuantity;
        private int _OrderFromStopLimitCloseBalance;
        private string _OrderFromStopLimitCloseStatusOrder;
        private int _OrderFromStopLimitCloseID;
        private long _OrderFromStopLimitCloseNumberOrder;
        private double _OrderFromStopLimitclosePriceOrder;

        #endregion

        #region public
        #region Заявка на открытие
        /// <summary>
        /// Время заявки на открытие
        /// </summary>
        public DateTime OpenDate
        {
            get { return _openDate; }
            set
            {
                if (_openDate != value)
                {
                    _openDate = value;
                    RaisePropertyChanged("OpenDate");
                }
            }
        }
        /// <summary>
        /// Операция заявки на открытие позиции
        /// </summary>
        public string OpenOperation
        {
            get { return _openOperation; }
            set
            {
                if (_openOperation != value)
                {
                    _openOperation = value;
                    RaisePropertyChanged("OpenOperation");
                }
            }
        }
        /// <summary>
        /// Общее количество в заявке на открытие позиции
        /// </summary>
        public int OpenQuantity
        {
            get { return _openQuantity; }
            set
            {
                if (_openQuantity != value)
                {
                    _openQuantity = value;
                    RaisePropertyChanged("OpenQuantity");
                }
            }
        }
        /// <summary>
        /// Исполненное количество контрактов на открытие позиции
        /// </summary>
        public int OpenBalance
        {
            get { return _openBalance; }
            set
            {
                if (_openBalance != value)
                {
                    _openBalance = value;
                    RaisePropertyChanged("OpenBalance");
                }
            }
        }
        /// <summary>
        /// Статус заявки на открытие позиции
        /// </summary>
        public string OpenStatusOrder
        {
            get { return _openStatusOrder; }
            set
            {
                if (_openStatusOrder != value)
                {
                    _openStatusOrder = value;
                    RaisePropertyChanged("OpenStatusOrder");
                }
            }
        }
        /// <summary>
        /// ID заявки на открытие позиции
        /// </summary>
        public int OpenID
        {
            get { return _openID; }
            set
            {
                if (_openID != value)
                {
                    _openID = value;
                    RaisePropertyChanged("OpenID");
                }
            }
        }
        /// <summary>
        /// Номер заявки на открытие позиции
        /// </summary>
        public long OpenNumberOrder
        {
            get { return _openNumberOrder; }
            set
            {
                if (_openNumberOrder != value)
                {
                    _openNumberOrder = value;
                    RaisePropertyChanged("OpenNumberOrder");
                }
            }
        }
        /// <summary>
        /// Цена в заявке на открытие позиции
        /// </summary>
        public double OpenPriceOrder
        {
            get { return _openPriceOrder; }
            set
            {
                if (_openPriceOrder != value)
                {
                    _openPriceOrder = value;
                    RaisePropertyChanged("OpenPriceOrder");
                }
            }
        }
        #endregion

        #region Заявка на закрытие
        /// <summary>
        /// Время заявки на закрытие
        /// </summary>
        public DateTime CloseDate
        {
            get { return _closeDate; }
            set
            {
                if (_closeDate != value)
                {
                    _closeDate = value;
                    RaisePropertyChanged("CloseDate");
                }
            }
        }
        /// <summary>
        /// Операция заявки на закрытие позиции
        /// </summary>
        public string CloseOperation
        {
            get { return _closeOperation; }
            set
            {
                if (_closeOperation != value)
                {
                    _closeOperation = value;
                    RaisePropertyChanged("CloseOperation");
                }
            }
        }
        /// <summary>
        /// Общее количество в заявке на закрытие позиции
        /// </summary>
        public int CloseQuantity
        {
            get { return _closeQuantity; }
            set
            {
                if (_closeQuantity != value)
                {
                    _closeQuantity = value;
                    RaisePropertyChanged("CloseQuantity");
                }
            }
        }
        /// <summary>
        /// Исполненное количество контрактов на закрытие позиции
        /// </summary>
        public int CloseBalance
        {
            get { return _closeBalance; }
            set
            {
                if (_closeBalance != value)
                {
                    _closeBalance = value;
                    RaisePropertyChanged("CloseBalance");
                }
            }
        }
        /// <summary>
        /// Статус заявки на закрытие позиции
        /// </summary>
        public string CloseStatusOrder
        {
            get { return _closeStatusOrder; }
            set
            {
                if (_closeStatusOrder != value)
                {
                    _closeStatusOrder = value;
                    RaisePropertyChanged("CloseStatusOrder");
                }
            }
        }
        /// <summary>
        /// ID заявки на закрытие позиции
        /// </summary>
        public int CloseID
        {
            get { return _closeID; }
            set
            {
                if (_closeID != value)
                {
                    _closeID = value;
                    RaisePropertyChanged("CloseID");
                }
            }
        }
        /// <summary>
        /// Номер заявки на закрытие позиции
        /// </summary>
        public long CloseNumberOrder
        {
            get { return _closeNumberOrder; }
            set
            {
                if (_closeNumberOrder != value)
                {
                    _closeNumberOrder = value;
                    RaisePropertyChanged("CloseNumberOrder");
                }
            }
        }
        /// <summary>
        /// Цена в заявке на закрытие позиции
        /// </summary>
        public double ClosePriceOrder
        {
            get { return _closePriceOrder; }
            set
            {
                if (_closePriceOrder != value)
                {
                    _closePriceOrder = value;
                    RaisePropertyChanged("ClosePriceOrder");
                }
            }
        }
        #endregion

        #region Заявка на закрытие Стоп-лимит
        /// <summary>
        /// Время стоп заявки на закрытие
        /// </summary>
        public DateTime StopLimitCloseDate
        {
            get { return _StopLimitCloseDate; }
            set
            {
                if (_StopLimitCloseDate != value)
                {
                    _StopLimitCloseDate = value;
                    RaisePropertyChanged("StopLimitCloseDate");
                }
            }
        }
        /// <summary>
        /// Операция стоп заявки на закрытие позиции
        /// </summary>
        public string StopLimitCloseOperation
        {
            get { return _StopLimitCloseOperation; }
            set
            {
                if (_StopLimitCloseOperation != value)
                {
                    _StopLimitCloseOperation = value;
                    RaisePropertyChanged("StopLimitCloseOperation");
                }
            }
        }
        /// <summary>
        /// Общее количество в стоп заявке на закрытие позиции
        /// </summary>
        public int StopLimitCloseQuantity
        {
            get { return _StopLimitCloseQuantity; }
            set
            {
                if (_StopLimitCloseQuantity != value)
                {
                    _StopLimitCloseQuantity = value;
                    RaisePropertyChanged("StopLimitCloseQuantity");
                }
            }
        }
        /// <summary>
        /// Исполненное количество контрактов в стоп заявке на закрытие позиции
        /// </summary>
        public int StopLimitCloseBalance
        {
            get { return _StopLimitCloseBalance; }
            set
            {
                if (_StopLimitCloseBalance != value)
                {
                    _StopLimitCloseBalance = value;
                    RaisePropertyChanged("StopLimitCloseBalance");
                }
            }
        }
        /// <summary>
        /// Статус стоп заявки на закрытие позиции
        /// </summary>
        public string StopLimitCloseStatusOrder
        {
            get { return _StopLimitCloseStatusOrder; }
            set
            {
                if (_StopLimitCloseStatusOrder != value)
                {
                    _StopLimitCloseStatusOrder = value;
                    RaisePropertyChanged("StopLimitCloseStatusOrder");
                }
            }
        }
        /// <summary>
        /// Результат стоп заявки на закрытие позиции (выставлена в систему)
        /// </summary>
        public string StopLimitCloseResult
        {
            get { return _StopLimitCloseResult; }
            set
            {
                if (_StopLimitCloseResult != value)
                {
                    _StopLimitCloseResult = value;
                    RaisePropertyChanged("StopLimitCloseResult");
                }
            }
        }
        /// <summary>
        /// ID стоп заявки на закрытие позиции
        /// </summary>
        public int StopLimitCloseID
        {
            get { return _StopLimitCloseID; }
            set
            {
                if (_StopLimitCloseID != value)
                {
                    _StopLimitCloseID = value;
                    RaisePropertyChanged("StopLimitCloseID");
                }
            }
        }
        /// <summary>
        /// Номер стоп заявки на закрытие позиции
        /// </summary>
        public long StopLimitCloseNumberOrder
        {
            get { return _StopLimitCloseNumberOrder; }
            set
            {
                if (_StopLimitCloseNumberOrder != value)
                {
                    _StopLimitCloseNumberOrder = value;
                    RaisePropertyChanged("StopLimitCloseNumberOrder");
                }
            }
        }
        /// <summary>
        /// Номер связанной заявки по стоп заявке на закрытие позиции
        /// </summary>
        public long StopLimitCloseNumberLinkidOrder
        {
            get { return _StopLimitCloseNumberLinkidOrder; }
            set
            {
                if (_StopLimitCloseNumberLinkidOrder != value)
                {
                    _StopLimitCloseNumberLinkidOrder = value;
                    RaisePropertyChanged("StopLimitCloseNumberLinkidOrder");
                }
            }
        }
        /// <summary>
        /// Цена в стоп заявке на закрытие позиции
        /// </summary>
        public double StopLimitClosePrice
        {
            get { return _StopLimitclosePriceOrder; }
            set
            {
                if (_StopLimitclosePriceOrder != value)
                {
                    _StopLimitclosePriceOrder = value;
                    RaisePropertyChanged("StopLimitclosePriceOrder");
                }
            }
        }
        #endregion стоп-заявка на закрытие позиции

        #region Заявка от Стоп-лимит на закрытие позиции
        /// <summary>
        /// Время заявки от стоп-заявки в заявке на закрытие
        /// </summary>
        public DateTime OrderFromStopLimitCloseDate
        {
            get { return _OrderFromStopLimitCloseDate; }
            set
            {
                if (_OrderFromStopLimitCloseDate != value)
                {
                    _OrderFromStopLimitCloseDate = value;
                    RaisePropertyChanged("OrderFromStopLimitCloseDate");
                }
            }
        }
        /// <summary>
        /// Операция  заявки от стоп-заявки на закрытие позиции
        /// </summary>
        public string OrderFromStopLimitCloseOperation
        {
            get { return _OrderFromStopLimitCloseOperation; }
            set
            {
                if (_OrderFromStopLimitCloseOperation != value)
                {
                    _OrderFromStopLimitCloseOperation = value;
                    RaisePropertyChanged("OrderFromStopLimitCloseOperation");
                }
            }
        }
        /// <summary>
        /// Общее количество в  заявке от стоп-заявки на закрытие позиции
        /// </summary>
        public int OrderFromStopLimitCloseQuantity
        {
            get { return _OrderFromStopLimitCloseQuantity; }
            set
            {
                if (_OrderFromStopLimitCloseQuantity != value)
                {
                    _OrderFromStopLimitCloseQuantity = value;
                    RaisePropertyChanged("OrderFromStopLimitCloseQuantity");
                }
            }
        }
        /// <summary>
        /// Исполненное количество контрактов в  заявке от стоп-заявки на закрытие позиции
        /// </summary>
        public int OrderFromStopLimitCloseBalance
        {
            get { return _OrderFromStopLimitCloseBalance; }
            set
            {
                if (_OrderFromStopLimitCloseBalance != value)
                {
                    _OrderFromStopLimitCloseBalance = value;
                    RaisePropertyChanged("OrderFromStopLimitCloseBalance");
                }
            }
        }
        /// <summary>
        /// Статус  заявки от стоп-заявки на закрытие позиции
        /// </summary>
        public string OrderFromStopLimitCloseStatusOrder
        {
            get { return _OrderFromStopLimitCloseStatusOrder; }
            set
            {
                if (_OrderFromStopLimitCloseStatusOrder != value)
                {
                    _OrderFromStopLimitCloseStatusOrder = value;
                    RaisePropertyChanged("OrderFromStopLimitCloseStatusOrder");
                }
            }
        }
        /// <summary>
        /// ID  заявки от стоп-заявки на закрытие позиции
        /// </summary>
        public int OrderFromStopLimitCloseID
        {
            get { return _OrderFromStopLimitCloseID; }
            set
            {
                if (_OrderFromStopLimitCloseID != value)
                {
                    _OrderFromStopLimitCloseID = value;
                    RaisePropertyChanged("OrderFromStopLimitCloseID");
                }
            }
        }
        /// <summary>
        /// Номер  заявки от стоп-заявки на закрытие позиции
        /// </summary>
        public long OrderFromStopLimitCloseNumberOrder
        {
            get { return _OrderFromStopLimitCloseNumberOrder; }
            set
            {
                if (_OrderFromStopLimitCloseNumberOrder != value)
                {
                    _OrderFromStopLimitCloseNumberOrder = value;
                    RaisePropertyChanged("OrderFromStopLimitCloseNumberOrder");
                }
            }
        }
        /// <summary>
        /// Цена в  заявки от стоп-заявке на закрытие позиции
        /// </summary>
        public double OrderFromStopLimitclosePriceOrder
        {
            get { return _OrderFromStopLimitclosePriceOrder; }
            set
            {
                if (_OrderFromStopLimitclosePriceOrder != value)
                {
                    _OrderFromStopLimitclosePriceOrder = value;
                    RaisePropertyChanged("OrderFromStopLimitclosePriceOrder");
                }
            }
        }
        #endregion стоп-заявка на закрытие позиции

        #endregion public

        public TradesOpen() { }

        #region event PropertyChangedEventHandler

        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion

        public TradesOpen(SerializationInfo info, StreamingContext context)
        {
            OpenDate = info.GetDateTime("OpenDate");
            OpenOperation = info.GetString("OpenOperation");
            OpenQuantity = info.GetInt32("OpenQuantity");
            OpenBalance = info.GetInt32("OpenBalance");
            OpenStatusOrder = info.GetString("OpenStatusOrder");
            OpenID = info.GetInt32("OpenID");
            OpenNumberOrder = info.GetInt64("OpenNumberOrder");
            OpenPriceOrder = info.GetDouble("OpenPriceOrder");

            CloseDate = info.GetDateTime("CloseDate");
            CloseOperation = info.GetString("CloseOperation");
            CloseQuantity = info.GetInt32("CloseQuantity");
            CloseBalance = info.GetInt32("CloseBalance");
            CloseStatusOrder = info.GetString("CloseStatusOrder");
            CloseID = info.GetInt32("CloseID");
            CloseNumberOrder = info.GetInt64("CloseNumberOrder");
            ClosePriceOrder = info.GetDouble("ClosePriceOrder");

            StopLimitCloseDate = info.GetDateTime("StopLimitCloseDate");
            StopLimitCloseOperation = info.GetString("StopLimitCloseOperation");
            StopLimitCloseQuantity = info.GetInt32("StopLimitCloseQuantity");
            StopLimitCloseBalance = info.GetInt32("StopLimitCloseBalance");
            StopLimitCloseStatusOrder = info.GetString("StopLimitCloseStatusOrder");
            StopLimitCloseResult = info.GetString("StopLimitCloseResult");
            StopLimitCloseID = info.GetInt32("StopLimitCloseID");
            StopLimitCloseNumberOrder = info.GetInt64("StopLimitCloseNumberOrder");
            StopLimitClosePrice = info.GetDouble("StopLimitclosePriceOrder");
            StopLimitCloseNumberLinkidOrder = info.GetInt64("StopLimitCloseNumberLinkidOrder");

            OrderFromStopLimitCloseDate = info.GetDateTime("OrderFromStopLimitCloseDate");
            OrderFromStopLimitCloseOperation = info.GetString("OrderFromStopLimitCloseOperation");
            OrderFromStopLimitCloseQuantity = info.GetInt32("OrderFromStopLimitCloseQuantity");
            OrderFromStopLimitCloseBalance = info.GetInt32("OrderFromStopLimitCloseBalance");
            OrderFromStopLimitCloseStatusOrder = info.GetString("OrderFromStopLimitCloseStatusOrder");
            OrderFromStopLimitCloseID = info.GetInt32("OrderFromStopLimitCloseID");
            OrderFromStopLimitCloseNumberOrder = info.GetInt64("OrderFromStopLimitCloseNumberOrder");
            OrderFromStopLimitclosePriceOrder = info.GetDouble("OrderFromStopLimitclosePriceOrder");
        }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("OpenDate", OpenDate);
            info.AddValue("OpenOperation", OpenOperation);
            info.AddValue("OpenQuantity", OpenQuantity);
            info.AddValue("OpenBalance", OpenBalance);
            info.AddValue("OpenStatusOrder", OpenStatusOrder);
            info.AddValue("OpenID", OpenID);
            info.AddValue("OpenNumberOrder", OpenNumberOrder);
            info.AddValue("OpenPriceOrder", OpenPriceOrder);

            info.AddValue("CloseDate", CloseDate);
            info.AddValue("CloseOperation", CloseOperation);
            info.AddValue("CloseQuantity", CloseQuantity);
            info.AddValue("CloseBalance", CloseBalance);
            info.AddValue("CloseStatusOrder", CloseStatusOrder);
            info.AddValue("CloseID", CloseID);
            info.AddValue("CloseNumberOrder", CloseNumberOrder);
            info.AddValue("ClosePriceOrder", ClosePriceOrder);

            info.AddValue("StopLimitCloseDate", StopLimitCloseDate);
            info.AddValue("StopLimitCloseOperation", StopLimitCloseOperation);
            info.AddValue("StopLimitCloseQuantity", StopLimitCloseQuantity);
            info.AddValue("StopLimitCloseBalance", StopLimitCloseBalance);
            info.AddValue("StopLimitCloseStatusOrder", StopLimitCloseStatusOrder);
            info.AddValue("StopLimitCloseResult", StopLimitCloseResult);
            info.AddValue("StopLimitCloseID", StopLimitCloseID);
            info.AddValue("StopLimitCloseNumberOrder", StopLimitCloseNumberOrder);
            info.AddValue("StopLimitclosePriceOrder", StopLimitClosePrice);
            info.AddValue("StopLimitCloseNumberLinkidOrder", StopLimitCloseNumberLinkidOrder);

            info.AddValue("OrderFromStopLimitCloseDate", OrderFromStopLimitCloseDate);
            info.AddValue("OrderFromStopLimitCloseOperation", OrderFromStopLimitCloseOperation);
            info.AddValue("OrderFromStopLimitCloseQuantity", OrderFromStopLimitCloseQuantity);
            info.AddValue("OrderFromStopLimitCloseBalance", OrderFromStopLimitCloseBalance);
            info.AddValue("OrderFromStopLimitCloseStatusOrder", OrderFromStopLimitCloseStatusOrder);
            info.AddValue("OrderFromStopLimitCloseID", OrderFromStopLimitCloseID);
            info.AddValue("OrderFromStopLimitCloseNumberOrder", OrderFromStopLimitCloseNumberOrder);
            info.AddValue("OrderFromStopLimitclosePriceOrder", OrderFromStopLimitclosePriceOrder);
        }
    }
}
